Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/pg

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/pg

TypeScript definitions for pg

  • 8.11.10
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4M
decreased by-45.71%
Maintainers
1
Weekly downloads
 
Created

What is @types/pg?

The @types/pg package provides TypeScript type definitions for the pg (node-postgres) library, which is a collection of Node.js modules for interfacing with your PostgreSQL database. It enables TypeScript developers to work with pg more efficiently by offering compile-time type checking and IntelliSense support in code editors.

What are @types/pg's main functionalities?

Client Connection

This feature allows you to connect to a PostgreSQL database using the Client class. The code sample demonstrates how to create a new client, connect to the database, execute a simple query, and then close the connection.

import { Client } from 'pg';

const client = new Client();
await client.connect();
await client.query('SELECT NOW()');
await client.end();

Pool Management

This feature enables efficient management of a pool of connections to the PostgreSQL database. The code sample shows how to create a pool, acquire a client from the pool, execute a query, release the client back to the pool, and finally close the pool.

import { Pool } from 'pg';

const pool = new Pool();
const client = await pool.connect();
try {
  const res = await client.query('SELECT NOW()');
} finally {
  client.release();
}
await pool.end();

Query with Parameters

This feature demonstrates how to execute a parameterized query to prevent SQL injection. The code sample illustrates inserting data into a table using parameters for the values.

import { Client } from 'pg';

const client = new Client();
await client.connect();
const text = 'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *';
const values = ['Brian', 'brian@example.com'];
const res = await client.query(text, values);
await client.end();

Other packages similar to @types/pg

FAQs

Package last updated on 13 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc